/**
 * 
 */
package rest_ws;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import jpa_objects.City;
import jpa_objects.Comment;
import jpa_objects.Event;
import jpa_objects.Event_report;
import jpa_objects.Player;
import jpa_objects.Sport;

import json_objects_received.JaxCommonClases;
import json_objects_received.WriteReview;

import json_objects_send.Basic_User;
import json_objects_send.Conversation;
import json_objects_send.Event_Info;
import json_objects_send.Full_User;
import json_objects_send.JSON_Message;
import json_objects_send.JSON_business;
import json_objects_send.JSON_event;
import json_objects_send.JSON_instructor;
import json_objects_send.JSON_notification;
import json_objects_send.JSON_player;
import json_objects_send.JSON_review;
import logic.CluvieMain;
import logic.CluviePlayer;



/**
 * @author Alejandro Casas
 * 
 *
 */
//http://localhost:81/Cluvie2.0/rest/common/get
@Path("/common")
//TODO los DAO's actualizar la base de datos, Poner JSON donde se necesite de llegada con la explicacion

public class RestCommonWS {

	
	
	@GET
	@Path(value="get/{nombre}")
	@Produces(MediaType.TEXT_PLAIN)
	public String getTestString(@PathParam("nombre") 
			String nombre)
	{
	
		return "Hello " +nombre+" this is a test get";
	}
	
	@POST
	@Path(value="json")
	@Produces(MediaType.TEXT_HTML)
	@Consumes(MediaType.APPLICATION_JSON)
	public String jsonTest(final JaxCommonClases.JaxEventInfo event)
	{
		
		return "this is the sports name: "+event.mailOwner;
	}
	
	@POST
	@Path(value="post")
	@Produces(MediaType.TEXT_HTML)
	public String postTestString(@FormParam("nombre") String nombre)
	{
		System.out.println(nombre);
		return "Hello " +nombre+" this is a test post";
	}
	
	@POST
	@Path(value="Feedback")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean Feedback(@FormParam("mail") String mail,
			@FormParam("subject") String subject,@FormParam("comment") String comment)
	{
		return (new CluvieMain()).writeFeedback(mail,subject,comment);
	}
	
	@POST
	@Path(value="GetUsersType")
	@Produces(MediaType.APPLICATION_JSON)
	public String GetUsersType(@FormParam("mail") String mail)
	{
		return (new CluvieMain()).getUsersType(mail);
	}
	
	@POST
	@Path(value="GetEventInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public Event_Info GetEventInfo(@FormParam("id") 
			long id,@FormParam("viewer") 
			String viewer)
	{
		return (new CluvieMain()).getEventInfo(id,viewer);
		
	}
	
	@POST
	@Path(value="GetEventparticipationRequest")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Basic_User> GetEventparticipationRequest(@FormParam("id") 
			long id)
	{
		return (new CluvieMain()).getEventParticipationRequests(id);
	}
	
	@POST
	@Path(value="AcceptEventParticpationRequest")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean AcceptEventParticpationRequest(@FormParam("eventId") 
			long eventId,@FormParam("mail") 
			String mail,@FormParam("nameFrom") 
			String nameFrom)
	{
		return (new CluvieMain()).acceptEventParticipationRequest(eventId,mail,nameFrom);
	}
	
	@POST
	@Path(value="RejectEventParticipationRequest")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean RejectEventParticipationRequest(@FormParam("eventId") 
			long eventId,@FormParam("mail") 
			String mail,@FormParam("nameFrom") 
			String nameFrom)
	{
		return (new CluvieMain()).rejectEventParticipationRequest(eventId,mail,nameFrom);
	}
	
	@POST
	@Path(value="GetEventRegisteredParticipants")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Basic_User> GetEventRegisteredParticipants(@FormParam("eventId") 
			long eventId,@FormParam("viewer") 
			String viewer)
	{
		return (new CluvieMain()).getEventRegisteredParticipants(eventId,viewer);
	}
	
	@POST
	@Path(value="GetUserConversations")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Conversation> GetUserConversations(@FormParam("mail") 
			String mail)
	{
		return (new CluvieMain()).getUserConversations(mail);
	}
	
	@POST
	@Path(value="GetConversationMessages")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_Message> GetConversationMessages(@FormParam("mailUser") 
			String mailUser,@FormParam("mailWith") 
			String mailWith)
	{
		return (new CluvieMain()).getUserMessages(mailUser,mailWith);
	}
	
	@POST
	@Path(value="GetUserBasicInfo")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public Basic_User GetUserBasicInfo(final json_objects_received.GetUserBasicInfo param)
	{
		System.out.println("aaaaaaaaaaaaa");
		System.out.println(param.getMail());
		System.out.println("aaaaaaaaaaaaa");
		return (new CluvieMain()).getUserBasicInfo(param.getMail(),param.getViewer());
	}  
	
	@POST
	@Path(value="SendMessage")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean SendMessage(@FormParam("mailFrom") 
			String mailFrom,@FormParam("mailTo") 
			String mailTo,@FormParam("title") 
			String title, @FormParam("message") 
			String message,@FormParam("nameFrom") 
			String nameFrom,@FormParam("miniPictureFrom") 
			String miniPictureFrom)
	{
		return (new CluvieMain()).sendMessage(mailFrom, mailTo, title, message,nameFrom,miniPictureFrom);
	}
	
	@POST
	@Path(value="SetStatus")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean SetStatus(@FormParam("mail") 
			String mail,@FormParam("status") 
			String status)
	{
		return (new CluvieMain()).setStatus(mail,status);
	}
	/*
	@POST
	@Path(value="ChangePassword/{mail}/{oldpass}/{newpass}")
	@Produces(MediaType.APPLICATION_JSON)
	//ESTE SERVICIO NO DEBE SER USADO NUNCA
	public String ChangePassword()
	{
		return null;
	}
	*/
	
	@POST
	@Path(value="GetUserReviews")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_review> GetUserReviews(@FormParam("mail") 
			String mail,@FormParam("viewer") 
			String viewer)
	{
		return (new CluvieMain()).getUserReviews(mail,viewer);
	}
	
	@POST
	@Path(value="ReportUser")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean ReportUser(@FormParam("mailReporter") 
			String mailReporter,@FormParam("mailReported") 
			String mailReported,@FormParam("message") 
			String message)
	{
		return (new CluvieMain()).reportUser(mailReported,mailReporter,message);
	}
	@POST
	@Path(value="Follow")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean Follow(@FormParam("mailFollower") 
			String mailFollower,@FormParam("mailFollowed") 
			String mailFollowed)
	{
		return (new CluvieMain()).follow(mailFollowed,mailFollower);
	}
	@POST
	@Path(value="Unfollow")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean Unfollow(@FormParam("mailFollower") 
			String mailFollower,@FormParam("mailFollowed") 
			String mailFollowed)
	{
		return (new CluvieMain()).unfollow(mailFollowed,mailFollower);
	}
	
	@POST
	@Path(value="WriteReview")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean WriteReview(final WriteReview param)
	{
		return (new CluvieMain()).writeReview(param.getMailFrom(),param.getMailTo(),param.getSport(),param.getCalification(),
				param.getTitle(),param.getMessage(),param.getNameFrom());
	}
	
	@POST
	@Path(value="GetFollowers")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Basic_User> GetFollowers(@FormParam("mail") 
			String mail,@FormParam("viewer") 
			String viewer)
	{
		return (new CluvieMain()).getFollowers(mail,viewer);
	}
	@POST
	@Path(value="ReportEvent")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean ReportEvent(@FormParam("eventId") 
			long eventId,@FormParam("mailReporter") 
			String mailReporter,@FormParam("message") 
			String message)
	{
		return (new CluvieMain()).reportEvent(eventId,mailReporter,message);
	}
	
	
	@POST
	@Path(value="VerifyUser")
	@Produces(MediaType.APPLICATION_JSON)
	public Basic_User VerifyUser(final json_objects_received.VerifyUser param)
	{
		return (new CluvieMain()).verifyUser(param.getMail(),param.getPassword());
	}

	@POST
	@Path(value="SearchPlayers")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_player> SearchPlayers(final json_objects_received.SearchPlayers param)
	{
		System.out.println("A: "+param.isPrivacy());
		return (new CluvieMain()).searchPlayers(param.getMail(),param.getSport(),param.getCity(),param.getCountry(),param.isPrivacy(),param.getDateFrom(),param.getDateTo());
	}
	@POST
	@Path(value="SearchBussiness")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_business> SearchBusiness(final json_objects_received.SearchBusiness param)
	{
		return (new CluvieMain()).searchBusiness(param.getMail(),param.getCity(),
				param.getCountry(),param.isPrivacy(),param.getSport(),param.getType());
	}
	@POST
	@Path(value="SearchCoaches")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_instructor> SearchCoaches(@FormParam("mail") String mail,
			@FormParam("sport") 
			String sport,@FormParam("city") 
			String city,@FormParam("country") 
			String country,@FormParam("privacy") 
			boolean privacy)
	{
		return (new CluvieMain()).searchCoaches(mail,sport,city,country,privacy);
	}
	@POST
	@Path(value="SearchEvents")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_event> SearchEvents(@FormParam("mail") String mail,
			@FormParam("sport") 
			String sport,@FormParam("city") 
			String city,@FormParam("country") 
			String country,@FormParam("privacy") 
			boolean privacy)
	{
		return (new CluvieMain()).searchEvents(mail,sport,city,country,privacy);
	}
	
	@POST
	@Path(value="SearchUsers")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Basic_User> SearchUsers(@FormParam("string") 
			String string,@FormParam("viewer") 
			String viewer)
	{
		return (new CluvieMain()).searchUsers(string,viewer);
	}
	@POST
	@Path(value="GeneralSearch")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public List<Basic_User> GeneralSearch(final json_objects_received.GeneralSearch param)
	{
		System.out.println("String: "+param.getString()+" viewer: "+param.getViewer());
		return (new CluvieMain()).generalSearch(param.getString(),param.getViewer());
	}
	@POST
	@Path(value="GetUserFriends")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Basic_User> GetUserFriends(@FormParam("mail") 
			String mail,@FormParam("viewer") 
			String viewer)
	{
		return (new CluvieMain()).getUserFriends(mail,viewer);
	}
	@POST
	@Path(value="GetPlayerInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public Full_User GetPlayerInfo(final JaxCommonClases.GetPlayerInfo param)
	{
		return (new CluvieMain()).getPlayerInfo(param.mail,param.viewer);
	}
	@POST
	@Path(value="GetCoachInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public Full_User GetCoachInfo(final JaxCommonClases.GetCoachInfo param)
	{
		return (new CluvieMain()).getCoachInfo(param.mail,param.viewer);
	}
	@POST
	@Path(value="GetBusinessInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public Full_User GetBusinessInfo(final JaxCommonClases.GetBusinessInfo param)
	{
		return (new CluvieMain()).getBusinessInfo(param.mail,param.viewer);
	}
	
	
	
	@POST
	@Path(value="CreateEvent")
	@Produces(MediaType.APPLICATION_JSON)
	public Event_Info CreateEvent(final JaxCommonClases.JaxEventInfo event)
	{
		
		return (new CluvieMain()).createEvent(event.mailOwner,event.nameOwner,event.title,event.address,
				event.description,event.ending_date,event.starting_date,event.lat,event.lng,
				event.miniPicture,event.picture,event.openings,event.privacy,event.sports,
				event.city,event.country);
	}
	
	@POST
	@Path(value="GetUserEvents")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_event> GetUserEvents(@FormParam("mail") 
			String mail,@FormParam("viewer") 
			String viewer)
	{
		return (new CluvieMain()).getUserEvents(mail,viewer);
	}
	@POST
	@Path(value="GetNotifications")
	@Produces(MediaType.APPLICATION_JSON)
	public List<JSON_notification> GetNotifications(@FormParam("mail") 
			String mail)
	{
		return (new CluvieMain()).getNotifications(mail);
	}
	
	@POST
	@Path(value="DeleteConversation")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteConversation(@FormParam("mailUser") 
			String mailUser,@FormParam("mailWith") 
			String mailWith)
	{
		return (new CluvieMain()).deleteConversation(mailUser,mailWith);
	}
	
	@POST
	@Path(value="DeleteMessage")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteMessage(@FormParam("mailUser") 
			String mailUser,@FormParam("messageId") 
			long messageId,@FormParam("mailWriter") 
			String mailWriter)
	{
		return (new CluvieMain()).deleteMessage(mailUser,messageId,mailWriter);
		
	}
	
	@POST
	@Path(value="GetSports")
	@Produces(MediaType.APPLICATION_JSON)
	public List<String> GetSports()
	{
		/*
		CluvieMain cm=new CluvieMain();
		return cm.getSports();
		*/
		List<String> l=new ArrayList<String>();
		for (int i = 0; i < 5; i++) {
			l.add("s"+i);
		}
		return l;
		
	}
	
	@POST
	@Path(value="GetCities")
	@Produces(MediaType.APPLICATION_JSON)
	public List<String> GetCities(@FormParam("country") 
			String country)
	{
		return (new CluvieMain()).getCities(country);
		
	}
	
	@POST
	@Path(value="DeleteReview")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteReview(@FormParam("id") 
			long id,@FormParam("mailWriter") 
			String mailWriter,@FormParam("mailTo") 
			String mailTo)
	{
		return (new CluvieMain()).deleteReview(id,mailWriter,mailTo);
		
	}
	@POST
	@Path(value="DeleteEvent")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteEvent(@FormParam("id") 
			long id,@FormParam("mailSession") 
			String mailSession)
	{
		return (new CluvieMain()).deleteEvent(id,mailSession);
		
	}
	@POST
	@Path(value="DeleteDiscount")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean DeleteDiscount(@FormParam("id") 
			long id,@FormParam("mailSession") 
			String mailSession)
	{
		return (new CluvieMain()).deleteDiscount(id,mailSession);
		
	}
	
	@POST
	@Path(value="WriteCommentToEvent")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean WriteCommentToEvent(@FormParam("eventId") 
			long eventId,@FormParam("mail") 
			String mail,@FormParam("message") 
			String message)
	{
		return (new CluvieMain()).writeCommentToEvent(eventId,mail,message);
		
	}
	
	@POST
	@Path(value="SendEventSuggestion")
	@Produces(MediaType.APPLICATION_JSON)
	public boolean SendEventSuggestion(@FormParam("mailSender") 
			String mailSender,@FormParam("mailTo") 
			String mailTo,@FormParam("eventId") 
			long eventId)
	{
		return new CluvieMain().sendEventSuggestion(mailSender,mailTo,eventId);
	}
	
	
}
